package com.example.weakreference;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.example.weakreference.bean.Car;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    WeakReference<Car> objectWeakReference;
    Car                car;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        ReferenceQueue referenceQueue = new ReferenceQueue();

        car = new Car();
        objectWeakReference = new WeakReference<>(car);

    }

    @OnClick(R.id.btn_activity_b)
    public void onActivityB(View view) {
        car = null;
        startActivity(new Intent(this, ActivityB.class));
    }

    @OnClick(R.id.btn_get)
    public void onGet(View view) {
        System.out.println(objectWeakReference.get());
    }
}
